package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RxManageurls;
import com.ruoyi.system.service.IRxManageurlsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 公用外链Controller
 *
 * @author hjf
 * @date 2025-05-12
 */
@RestController
@RequestMapping("/hmk/manageurls")
public class RxManageurlsController extends BaseController {
    @Autowired
    private IRxManageurlsService rxManageurlsService;

    /**
     * 查询公用外链列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:manageurls:list')")
    @GetMapping("/list")
    public TableDataInfo list(RxManageurls rxManageurls) {
        if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
            rxManageurls.setIsHidden(1);
        }
        startPage();
        List<RxManageurls> list = rxManageurlsService.selectRxManageurlsList(rxManageurls);
        return getDataTable(list);
    }

    /**
     * 导出公用外链列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:manageurls:export')")
    //@Log(title = "公用外链", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RxManageurls rxManageurls) {
        List<RxManageurls> list = rxManageurlsService.selectRxManageurlsList(rxManageurls);
        ExcelUtil<RxManageurls> util = new ExcelUtil<RxManageurls>(RxManageurls.class);
        util.exportExcel(response, list, "公用外链数据");
    }

    /**
     * 获取公用外链详细信息
     */
    @PreAuthorize("@ss.hasPermi('hmk:manageurls:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(rxManageurlsService.selectRxManageurlsById(id));
    }

    /**
     * 新增公用外链
     */
    @PreAuthorize("@ss.hasPermi('hmk:manageurls:add')")
    //@Log(title = "公用外链", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RxManageurls rxManageurls) {
        rxManageurls.setIsHidden(1);
        rxManageurls.setTime(System.currentTimeMillis() / 1000);
        return toAjax(rxManageurlsService.insertRxManageurls(rxManageurls));
    }

    /**
     * 修改公用外链
     */
    @PreAuthorize("@ss.hasPermi('hmk:manageurls:edit')")
    //@Log(title = "公用外链", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RxManageurls rxManageurls) {
        return toAjax(rxManageurlsService.updateRxManageurls(rxManageurls));
    }

    /**
     * 删除公用外链
     */
    @PreAuthorize("@ss.hasPermi('hmk:manageurls:remove')")
    //@Log(title = "公用外链", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rxManageurlsService.deleteRxManageurlsByIds(ids));
    }
}
